﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Quizz.DataRepository.Models;
using Quizz.Service.Services;
using Quizz.QuizzProjectService.Models;

namespace Quizz.QuizzProjectService
{
    public partial class QuizzProjectService
    {
        public User UserGetById(long id)
        {
            using (var service = new UserService())
            {
                return service.GetById(id);
            }
        }

        public IList<User> UserGetAll()
        {
            using(var service = new UserService())
            {
                return service.GetAll().ToList();
            }
        }

        public User UserGetByEmail(string email)
        {
            using (var service = new UserService())
            {
                return service.GetByEmail(email);
            }
        }

        public void UserInsert(User user)
        {
            using (var service = new UserService())
            {
                service.Insert(user);
            }
        }

        public void UserUpdate(User user)
        {
            using (var service = new UserService())
            {
                service.Update(user);
            }
        }

        public bool UserDelete(long id)
        {
            using (var service = new UserService())
            {
                return service.Delete(id);
            }
        }

        public bool UserIsEmailAvailable(string email)
        {
            using(var service = new UserService())
            {
                return service.IsEmailAvailable(email);
            }
        }

        public IList<User> UserGetByRole(long role)
        {
            using (var service = new UserService())
            {
                return service.GetByRole(role).ToList();
            }
        }

        public UserPageResult UserGetPage(int page, int count, string orderCol)
        {
            using (var service = new UserService())
            {
                var result = new UserPageResult();
                var itemCount = 0;
                var items = service.GetUserPage(page, count, orderCol, ref itemCount);

                result.ResultCount = itemCount;
                result.Users = items.ToList();
                return result;
            }
        }

        public UserPageResult UserGetPageSearch(int page, int count, string orderCol, string keyword)
        {
            using (var service = new UserService())
            {
                var result = new UserPageResult();
                var itemCount = 0;
                var items = service.GetUserPage(page, count, orderCol, keyword, ref itemCount);

                result.ResultCount = itemCount;
                result.Users = items.ToList();
                return result;
            }
        }
    }
}